import request from '../../utils/request';

// 客户信息接口
export interface CustomerVO {
  id?: number;
  name: string;
  followUpStatus?: boolean;
  contactLastTime?: Date;
  contactLastContent?: string;
  contactNextTime?: Date;
  ownerUserId?: number;
  ownerUserName?: string;
  ownerUserDept?: string;
  lockStatus?: boolean;
  dealStatus?: boolean;
  mobile?: string;
  telephone?: string;
  qq?: string;
  wechat?: string;
  email?: string;
  areaId?: number;
  areaName?: string;
  detailAddress?: string;
  industryId?: number;
  level?: number;
  source?: number;
  remark?: string;
  creator?: string;
  creatorName?: string;
  createTime?: Date;
  updateTime?: Date;
}

// 客户分页查询参数
export interface CustomerPageParams {
  pageNo?: number;
  pageSize?: number;
  name?: string;
  mobile?: string;
  industryId?: number;
  level?: number;
  source?: number;
  ownerUserId?: number;
}

// 客户转移参数
export interface CustomerTransferParams {
  ids: number[];
  newOwnerUserId: number;
}

// 客户 API
export const CustomerApi = {
  // 查询客户分页
  getCustomerPage: async (params: CustomerPageParams) => {
    return await request.get('/crm/customer/page', { params });
  },

  // 查询客户详情
  getCustomer: async (id: number) => {
    return await request.get(`/crm/customer/${id}`);
  },

  // 新增客户
  createCustomer: async (data: CustomerVO) => {
    return await request.post('/crm/customer', data);
  },

  // 修改客户
  updateCustomer: async (data: CustomerVO) => {
    return await request.put('/crm/customer', data);
  },

  // 删除客户
  deleteCustomer: async (id: number) => {
    return await request.delete(`/crm/customer/${id}`);
  },

  // 锁定/解锁客户
  lockCustomer: async (id: number, lockStatus: boolean) => {
    return await request.put(`/crm/customer/${id}/lock`, { lockStatus });
  },

  // 转移客户
  transferCustomer: async (data: CustomerTransferParams) => {
    return await request.put('/crm/customer/transfer', data);
  },

  // 获取客户简单列表
  getCustomerSimpleList: async () => {
    return await request.get('/crm/customer/simple-list');
  },

  // 导出客户
  exportCustomer: async (params: CustomerPageParams) => {
    return await request.get('/crm/customer/export', { params, responseType: 'blob' });
  },

  // 获取导入模板
  getImportTemplate: () => {
    return request.get('/crm/customer/import-template', { responseType: 'blob' });
  },

  // 导入客户
  importCustomer: async (file: File) => {
    const formData = new FormData();
    formData.append('file', file);
    return await request.post('/crm/customer/import', formData);
  }
};